define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'rgjubao/hsh/index' + location.search,
                    add_url: 'rgjubao/hsh/add',
                    edit_url: 'rgjubao/hsh/edit',
                    del_url: 'rgjubao/hsh/del',
                    multi_url: 'rgjubao/hsh/multi',
                    import_url: 'rgjubao/hsh/import',
                    table: 'rgjubao_hsh',
                }
            });

            var table = $("#table");
            var initstatus = true;//状态初始化
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                queryParams:function(params){
                    filter = JSON.parse(params.filter);
                    op = JSON.parse(params.op);
                    if(initstatus && !filter.status){
                        filter.status = Config.status ;//默认待处理
                        op.status = '=';
                        params.filter = JSON.stringify(filter);
                        params.op = JSON.stringify(op);
                    }
                    initstatus = false;
                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'no', title: __('No'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"personal":__('Type personal'),"company":__('Type company')}, formatter: Table.api.formatter.normal},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'r_type', title: __('R_type'), searchList: {"personal":__('R_type personal'),"company":__('R_type company')}, formatter: Table.api.formatter.normal},
                        {field: 'r_name', title: __('R_name'), operate: 'LIKE'},
                        {field: 'r_sex', title: __('R_sex'), searchList: {"0":__('R_sex 0'),"1":__('R_sex 1'),"2":__('R_sex 2')}, formatter: Table.api.formatter.normal},
                        {field: 'r_id_info', title: __('R_id_info'), searchList: {"0":__('R_id_info 0'),"1":__('R_id_info 1'),"2":__('R_id_info 2'),"3":__('R_id_info 3'),"4":__('R_id_info 4'),"5":__('R_id_info 5'),"6":__('R_id_info 6'),"7":__('R_id_info 7')}, formatter: Table.api.formatter.normal},
                        {field: 'r_job', title: __('R_job'), operate: 'LIKE'},
                        {field: 'r_phone', title: __('R_phone'), operate: 'LIKE'},
                        {field: 'r_address', title: __('R_address'), operate: 'LIKE'},
                        {field: 'r_birthplace', title: __('R_birthplace'), operate: 'LIKE'},
                        {field: 'f_address', title: __('F_address'), operate: 'LIKE'},
                        {field: 'f_starttime', title: __('F_starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY"},
                        {field: 'f_endtime', title: __('F_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY"},
                        {field: 'f_gang', title: __('F_gang'), searchList: {"1":__('F_gang 1'),"2":__('F_gang 2'),"3":__('F_gang 3'),"4":__('F_gang 4'),"5":__('F_gang 5')}, formatter: Table.api.formatter.normal},
                        {field: 'f_charge', title: __('F_charge'), searchList: {"1":__('F_charge 1'),"2":__('F_charge 2'),"3":__('F_charge 3'),"4":__('F_charge 4'),"5":__('F_charge 5'),"6":__('F_charge 6'),"7":__('F_charge 7'),"8":__('F_charge 8'),"9":__('F_charge 9'),"10":__('F_charge 10'),"11":__('F_charge 11'),"12":__('F_charge 12'),"13":__('F_charge 13'),"14":__('F_charge 14'),"15":__('F_charge 15'),"16":__('F_charge 16'),"17":__('F_charge 17'),"18":__('F_charge 18'),"19":__('F_charge 19')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'f_industry', title: __('F_industry'), searchList: {"1":__('F_industry 1'),"2":__('F_industry 2'),"3":__('F_industry 3'),"4":__('F_industry 4'),"5":__('F_industry 5'),"6":__('F_industry 6'),"7":__('F_industry 7'),"8":__('F_industry 8'),"9":__('F_industry 9'),"10":__('F_industry 10'),"11":__('F_industry 11'),"12":__('F_industry 12'),"13":__('F_industry 13'),"14":__('F_industry 14'),"15":__('F_industry 15'),"16":__('F_industry 16')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'f_content', title: '基本案情', operate: 'LIKE'},
                        {field: 's_exist', title: __('S_exist'), searchList: {"0":__('S_exist 0'),"1":__('S_exist 1'),"2":__('S_exist 2')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 's_name', title: __('S_name'), operate: 'LIKE'},
                        {field: 's_id_info', title: __('S_id_info'), searchList: {"1":__('S_id_info 1'),"2":__('S_id_info 2'),"3":__('S_id_info 3'),"4":__('S_id_info 4'),"5":__('S_id_info 5'),"0":__('S_id_info 0')}, formatter: Table.api.formatter.normal},
                        {field: 's_job', title: __('S_job'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY-MM-DD"},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            // $(document).on("change", "#c-r_type", function(){
            //     //变更后的回调事件
            //     if($(this).val() == 'company'){
            //         console.log('company')
            //         $(".r_type_personal").toggleClass("hide", true);
            //     }else if($(this).val() == 'personal'){
            //         console.log('personal')
            //         $(".r_type_personal").toggleClass("hide", false);
            //     }

            //     // console.log($(this).val())
            // });
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
                
            }
        }
    };
    return Controller;
});
